﻿using Microsoft.Extensions.Configuration;
using System;

namespace Loong.Configuration
{
    public class DbConfigurationSource : IConfigurationSource
    {
        private readonly Action<DbConfigurationOptionsBuilder> _action;

        public DbConfigurationSource(Action<DbConfigurationOptionsBuilder> action)
        {
            _action = action;
        }

        public IConfigurationProvider Build(IConfigurationBuilder builder)
        {
            DbConfigurationOptionsBuilder optionsBuilder = new DbConfigurationOptionsBuilder();
            _action(optionsBuilder);

            return optionsBuilder.Options.ConfigurationProvider;
        }
    }
}
